package cn.edu.cqu.test;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import cn.edu.cqu.domains.AcademicNews;

public class Crawler
{
	public static void main(String[] args) throws IOException
	{
		Document doc = Jsoup.connect("http://www.cs.cqu.edu.cn/xyxw.htm").get();
		Elements links = doc.select("ul").first().select("li");
		for (Element element : links)
		{
			AcademicNews academicNews = new AcademicNews();
			String url = "http://www.cs.cqu.edu.cn/" + element.select("a").get(1).attr("href");
			String title =  element.select("a").get(1).attr("title");
			academicNews.setaNewsURL(url);
			academicNews.setaNewsTitle(title);
			Document newDoc = Jsoup.connect(url).get();
			Elements p = newDoc.select("p");
			for (int i = 0; i < p.size()-1; i++) {//最后一个P不是正文
				System.out.println(p.get(i).html());
			}
			System.out.println("-----");
		}
	}
}
